import React, { Component } from 'react'
import { Form, Icon, Input, Button, Checkbox } from 'antd'
import styles from './index.css'
const FormItem = Form.Item

class Login extends Component {

  constructor(props) {
    super(props)
    this.state = {
      username: '',
      password: ''
    }
  }

  onInputChange(e) {
    let inputName = e.target.name
    let inputValue = e.target.value
    this.setState({ 
      [inputName]: inputValue
    })
  }

  handleSubmit(e) {
    e.preventDefault();
    this.props.history.push('/manager')
  }
  onKeyUp(e) {
    if (e.keyCode === 13) {
      this.handleSubmit(e)
    }
  }



  render() {
    return (
      <div className={styles.loginPage}>
        <Form className={styles.form}>
          <h1 className={styles.title}>欢迎，请登陆！</h1>
          <FormItem>
            <Input name="username" onKeyUp={e => this.onKeyUp(e)} onChange={e => this.onInputChange(e)} prefix={<Icon type="user" style={{ color: 'rgba(0,0,0,.25)' }} />} placeholder="用户名" />
          </FormItem>
          <FormItem>
            <Input name="password" onKeyUp={e => this.onKeyUp(e)} onChange={e => this.onInputChange(e)} prefix={<Icon type="lock" style={{ color: 'rgba(0,0,0,.25)' }} />} type="password" placeholder="密码" />
          </FormItem>
          <FormItem>
            <Checkbox className={styles.remeber}>记住我</Checkbox>
            <Button type="primary" onClick={e => this.handleSubmit(e)} style={{ width: '100%' }}>
              登陆
          </Button>
          </FormItem>
        </Form>
      </div>
    )
  }
}

export default Form.create()(Login)